/**
 *  This file is part of TaoBaoItemImporter.
 *
 *   TaoBaoItemImporter is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   TaoBaoItemImporter is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with TaoBaoItemImporter.  If not, see <http://www.gnu.org/licenses/>. 
 */

package com.googlecode.ulysses.taobao.data;
import java.util.*;

/**
 * @author Hegen <lhegen@gmail.com>
 *
 */
public class PropertyNameParser {
	private String props_name;
	private HashMap<String, ArrayList<String>> pname_to_vname = null;
	
	public PropertyNameParser(){
		props_name = "";
		pname_to_vname = new HashMap<String, ArrayList<String>>();
	}
	
	public PropertyNameParser(String props_name){
		this.props_name = props_name;
		pname_to_vname = new HashMap<String, ArrayList<String>>(); 
	}
	
	
	public void CreatePidVidValue(String levelOneRegex, String levelTwoRegex){
		String[] levelOneResult = this.props_name.split(levelOneRegex);
		//Build up the HashMap
		for(String elem:levelOneResult){
			String[] levelTwoResult = elem.split(levelTwoRegex);
			
			//The levelTwoResult array size must be equal 4
			if(levelTwoResult.length == 4)
			{
				ArrayList<String> ret = pname_to_vname.get(levelTwoResult[2]);
				if(ret == null)
				{
					ret = new ArrayList<String>();
					ret.add(levelTwoResult[3]);
					pname_to_vname.put(levelTwoResult[2], ret);
				}
				else
				{
					ret.add(levelTwoResult[3]);
				}
			}
		}
	}

	public HashMap<String, ArrayList<String>> getPname_to_vname() {
		return pname_to_vname;
	}
	
	public ArrayList<String> getPropertyValue(String key)
	{
		return pname_to_vname.get(key);
	}
}
